package io.renren.modules.medical.controller;

import java.util.Arrays;
import java.util.Map;
import io.renren.common.result.Result;
import io.renren.common.utils.PageUtils;
import io.renren.common.validator.group.AddGroup;
import io.renren.common.validator.group.UpdateGroup;
import io.renren.modules.medical.service.HealthEducationService;
import io.renren.modules.medical.vo.medicalVo.HealthEducationSaveVo;
import io.renren.modules.medical.vo.medicalVo.StatusVo;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 健康教育
 *
 * @author luosheng
 * @email luoshengshuai@foxmail.com
 * @date 2023-04-13 15:54:58
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/medical/health/education")
public class HealthEducationController {

    private final HealthEducationService healthEducationService;

    /**
     * 列表
     */
    @RequiresPermissions("healtheducation:list")
    @RequestMapping("/list")
    public Result<PageUtils> list(@RequestParam Map<String, Object> params) {
        PageUtils page = healthEducationService.queryPage(params);

        return Result.success(page);
    }


    /**
     * 信息
     */
    @RequiresPermissions("healtheducation:info")
    @RequestMapping("/info/{id}")
    public Result<Map<String, Object>> info(@PathVariable("id") Long id) {
        Map<String, Object> resultMap = healthEducationService.getInfoById(id);
        return Result.success(resultMap);
    }

    /**
     * 保存
     */
    @RequiresPermissions("healtheducation:save")
    @PostMapping("/save")
    public Result<String> save(@Validated(AddGroup.class) @RequestBody HealthEducationSaveVo healthEducation) {
        healthEducationService.saveHealthEducation(healthEducation);
        return Result.success(null);
    }

    /**
     * 修改
     */
    @RequiresPermissions("healtheducation:update")
    @PostMapping("/update")
    public Result<String> update(@Validated(UpdateGroup.class) @RequestBody HealthEducationSaveVo healthEducation) {
        healthEducationService.updateHealthEducation(healthEducation);
        return Result.success(null);
    }

    /**
     * 删除
     */
    @RequiresPermissions("healtheducation:delete")
    @PostMapping("/delete")
    public Result<String> delete(@RequestBody Long[] ids) {
        healthEducationService.removeHealthEducation(Arrays.asList(ids));
        return Result.success(null);
    }

    /**
     * 修改状态
     */
    @RequiresPermissions("healtheducation:update")
    @PostMapping("/updateStatus")
    public Result<String> updateStatus(@RequestBody StatusVo statusVo) {
        healthEducationService.updateStatus(statusVo);
        return Result.success(null);
    }

    /**
     * 审核
     */
    @RequiresPermissions("healtheducation:audit")
    @PostMapping("/audit")
    public Result<String> audit(@RequestBody StatusVo statusVo) {
        healthEducationService.updateStatus(statusVo);
        return Result.success(null);
    }

}
